package com.groupbuying.customer.mq;

import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Properties;

/**
 * describe:
 *
 * @author zhaopengjun
 * @date 2019/5/17 16:20
 */
@Component
public class CustomerMQProductor {
    public static final Logger LOGGER = LoggerFactory.getLogger(CustomerMQProductor.class);

    public CustomerMQProductor() {
    }

    @Bean
    public Producer getYsReturnProducer() {
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.AccessKey, CustomerMQConfig.ACCESS_KEY);
        properties.put(PropertyKeyConst.SecretKey, CustomerMQConfig.SECRET_KEY);
        properties.put(PropertyKeyConst.NAMESRV_ADDR, CustomerMQConfig.NAMESRV_ADDR);
        Producer producer = ONSFactory.createProducer(properties);
        try {
            producer.start();
            //LOGGER.info("producer is start !!!  groupId:{" + YsReturnMQConfig.GROUP_ID + "}");
        } catch (Exception var4) {
            //LOGGER.error(String.format("producer is error  groupId:{" + YsReturnMQConfig.GROUP_ID + "}", var4.getMessage(), var4));
        }

        return producer;
    }
}
